<?php

include_once ('../../utilities.php')

?>
<!DOCTYPE html>
<html>
<head>
	<link rel="stylesheet" type="text/css" href="../../reset.css">
	<link rel="stylesheet" type="text/css" href="../../mainStyle.css">
	<link rel="stylesheet" type="text/css" href="../../searchButton.css">
	<title>Email Change</title>
</head>
<body>

	<div id="container">
		<?php

$root = '../../';
include_once ('../../header.php')

?>
        
		<div id="page-body">
		<?php

if (!empty($_POST['email']) && !empty($_SESSION['LoggedIn']) && !empty($_SESSION['User']))
{
    //Info posted to form
    $user = unserialize($_SESSION['User']);
    if (checkEmail($_POST['email']))
    {
        //Email is valid, set the user's email (changes database entry too)
        $user->setEmail($_POST['email']);
        $_SESSION['User'] = serialize($user);

?>
					<p>Your email has been changed. Please <a href="../">click here to return to your account page</a>.</p>
					<?php

    } else
    {

?>
					<p>Sorry, the new email was invalid. Please <a href="./">click here to try again</a>.</p>
					<?php

    }
} elseif (!empty($_SESSION['LoggedIn']) && !empty($_SESSION['User']))
{ //If they are logged in, show form to input email information
    $user = unserialize($_SESSION['User']);

?>
				
				<p>Please input a valid email address</p>
				
				<form method="post" action="./" name="emailform" id="emailform">
				<fieldset>
					<label for="email">New Email:</label><input type="text" name="email" id="email" /><br><br>
					<input type="submit" name="Submit" id="Submit" value="Submit" />
				</fieldset>
				</form>
				
				<?php

} else
{

?>
					
			   <p>You must login to view this page.</p>
									
			   <?php

}

?>
		</div>
		
		<?php

include_once ('../../footer.php')

?>
	</div>

</body>
</html>